package com.liantong.client.listener;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;

import com.liantong.service.util.Constant;
import com.liantong.util.StringUtil;

public class AppPropertyConstListener implements ServletRequestListener {

	/*
	 * (non-Javadoc)
	 * @see javax.servlet.ServletRequestListener#requestDestroyed(javax.servlet.
	 * ServletRequestEvent)
	 */
	@Override
	public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * @see
	 * javax.servlet.ServletRequestListener#requestInitialized(javax.servlet
	 * .ServletRequestEvent)
	 */
	@Override
	public void requestInitialized(ServletRequestEvent servletRequestEvent) {

		if (StringUtil.isBlank(Constant.APP_PATH)) {

			HttpServletRequest request = (HttpServletRequest) servletRequestEvent.getServletRequest();

			String serverPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + ""
					+ request.getContextPath();

			Constant.APP_PATH = serverPath;
		}
	}
}
